import * as UI from "../ui.js"
import {Module} from "../framework.js"
import * as SidebarEvent from "./sidebar-event.js"
import D from "../delegator.js"
import SidebarContent from "./sidebar-content.js"

export default class Sidebar extends Module {
    constructor(appDispatcher) {
        super(appDispatcher);
        this._ui = UI.UISidebar();

        this._ui.menuListElement.onclick = e => {
            D(e.target);
            while(D.HasTarget()) {
                if(D.HasAttribute('data-slog-menu')) {
                    const _menu = D.GetDatasetValue('slogMenu');
                    switch(_menu) {
                        case "search":
                            this.Dispatch(SidebarEvent.SearchClickedEvent());
                            break;
                        case "new":
                            this.Dispatch(SidebarEvent.NewNoteClickedEvent());
                            break;
                        case "setting":
                            this.Dispatch(SidebarEvent.SettingClickedEvent());
                            break;
                    }
                    return;
                }
                D.SetParentAsTarget();
            }
        }

        this._content = new SidebarContent(this._dispatcher);
    }
}

